﻿using Koala.Pro.CodeGenerator.UI.Common;
using Koala.Pro.CodeGenerator.UI.DatabaseModel;
using Koala.Pro.CodeGenerator.UI.DatabaseModel.Schema;

namespace Koala.Pro.CodeGenerator.UI
{
    public class GlobalControl
    {
        public FrmMain MainView;

        public DbInstanceInfo DbInstance;

        public string AssemblyTypeShortName
        {
            get
            {
                string text = null;
                string path = "DatabaseSetting.xml";
                DatabaseSetting[] array = (DatabaseSetting[])XmlUtils.LoadObjectFromXml(path, typeof(DatabaseSetting[]));
                DatabaseSetting[] array2 = array;
                foreach (DatabaseSetting databaseSetting in array2)
                {
                    if (DbInstance.DatabaseType == databaseSetting.DatabaseType)
                    {
                        text = databaseSetting.AssemblyType;
                        break;
                    }
                }
                if (text != null)
                {
                    int num = text.LastIndexOf(".");
                    text = text.Substring(num + 1).ToLower();
                }
                return text;
            }
        }

        public List<string> SelectedTableNames = new List<string>();

        public void SaveLanguage(string cultureName)
        {

        }

        public void CloseAllDocuments()
        {
            Program.global.MainView.CloseAllDocuments();
        }

        public byte GetNodeLevel(TreeNode n)
        {
            byte b = 1;
            while (n.Parent != null)
            {
                n = n.Parent;
                b++;
            }
            return b;
        }
    }
}
